package com.StarStudio.DAO;


import com.ruoyi.common.core.Entity.UserInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
@SuppressWarnings("all")
public interface UserInfoDAO {

    List<UserInfo> findUserInfoList(UserInfo userInfo);


    @Insert("insert into user_info values (#{id},#{real_name},#{card_num},#{card_type},#{icbc_card_num},#{avatar},#{mobile},#{hours},#{beans}," +
            "#{star},#{beans_spend_day},#{beans_spend_total},#{coupons_spend_day},#{coupons_value_spend_day},#{coupons_spend_total}," +
            "#{coupons_value_spend_total},#{first_login_time},#{last_login_time})")
    void UserInfoAdd(UserInfo userInfo);

    int updateUserInfo(UserInfo userInfo);

    @Select("select count(0) from user_info where id = #{id} and real_name = #{real_name} and card_num = #{card_num}")
    int findByCondition(UserInfo userInfo);

    @Select("SELECT * from user_info where id = #{id}")
    UserInfo findByUser_id(long id);

    @Update("update user_info set beans_spend_day = 0,coupons_spend_day = 0,coupons_value_spend_day = 0")
    void updateUserInfoPerDay();

    @Select("select count(0) from user_info")
    long findAllRecordNumber();

    @Select("select count(0) from user_info where date_format(last_login_time,'%Y-%m-%d') = #{today}")
    int today_login_user_number(String today);

    @Select("select count(0) from user_info where beans_spend_day != 0")
    int today_purchase_user_number();

    @Select("SELECT SUM(beans_spend_day) FROM user_info")
    int Beans_spend_today();

    @Select("SELECT SUM(beans_spend_total) FROM user_info")
    int Beans_spend_total();

    @Select("SELECT SUM(coupons_spend_day) FROM user_info")
    int Coupons_spend_today();

    @Select("SELECT SUM(coupons_value_spend_day) FROM user_info")
    double Coupons_value_spend_today();

    @Select("SELECT SUM(coupons_spend_total) FROM user_info")
    int Coupons_spend_total();
    @Select("SELECT SUM(coupons_value_spend_total) FROM user_info")
    double Coupons_value_spend_total();

    @Select("select count(0) from user_info where beans_spend_total > 0")
    int totalPurchseUserNumber();

    @Update("update user_info set beans = beans + #{increment} where id = #{userId}")
    void updateUserBeans(@Param("userId") Long userId,@Param("increment") Integer increment);

    @Select("select beans from user_info where id = #{userId}")
    Integer getUserBeans(Long userId);
}
